#!/bin/bash ### Matches and replaces the string, useful for season stuff for kodi ### MAKE SURE $file IS IN QUOTES ### look ahead look behind helped "$matchstring(?=\d+)" matches only if numbers follow it matchstring="Kyoukai_no_Kanata_-_" replacestring="Kyoukai_no_Kanata_-_S01E" input_filetype="mkv" files_path="/media/user1/2TB-ORICO/#Videos/#Anime/Beyond The Boundary/[Unoffical-Batch][UTW] Kyoukai No Kanata - Beyond The Boundary [720p][MKV]/" for file in "$files_path"*; do echo $file rename "s/$matchstring(?=\d+)/$replacestring/" "$file" done